import { Component, OnInit } from '@angular/core';
import { Observable } from "rxjs";
import { Http, Headers } from "@angular/http";
import "rxjs/Rx";  //这个是引用map方法引的。

@Component({
  selector: 'app-porduct',
  templateUrl: './porduct.component.html',
  styleUrls: ['./porduct.component.css']
})
export class PorductComponent implements OnInit {

  // dataSource:Observable<any>;
  // products: Array<any>= [];

  products: Observable<any>;//流

  constructor(private http:Http) { 

    let myHeaders: Headers = new Headers();
    myHeaders.append("ismeAAAA","BASEC 123456")

    this.products = this.http.get('/api/products', {headers: myHeaders}).map((res)=> res.json()); //这个只是 定义了一个请求。真正发送的 是下面的。subscribe
    //利用流时把我们的dataSource改成products
  }

  ngOnInit() {
    // this.dataSource.subscribe(
    //   (data) => this.products = data
    // )
  }

}
